import create from '../../utils/create2.js'
create({
  /**
   * 组件的属性列表
   */
  properties: {
    list: {
      type: Array,
      value: [],
      observer: 'listChange'
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    show: false,
    modal: false,
    title: '友情提示',
    roomId: '',
    type: '',
    index: -1,
    pIndex: -1
  },

  /**
   * 组件的方法列表
   */
  methods: {
    showRoom() {
      this.setData({
        show: true
      })
    },
    hideRoom() {
      this.setData({
        show: false
      })
    },
    listChange(newValue, oldValue) {
    },
    selectRoom(e) {
      const { id, status, tip, date, room, size, type, index, pnx } = e.currentTarget.dataset
      if (status === 1) {
        this.setData({
          modal: true,
          tips: '请选择别的包间!'
        })
      } else {
        this.store.data.roomId = id
        this.store.data.room = e.currentTarget.dataset
        this.setData({
          modal: true,
          title: '是否选择',
          tips: tip,
          type,
          index,
          pIndex: pnx
        })
      }
    },
    cancel() {
      this.store.data.roomId = ''
      this.update()
      this.setData({
        modal: false
      })
    },
    ok() {
      const { roomId } = this.store.data
      const { type, index, pIndex } = this.data
      if (pIndex === -1) {
        this.setData({
          modal: false,
        })
        return
      }
      this.store.data.roomList = this.store.data.roomList.map(item => {
        item.noon.map(noon => noon.is_had_order = 0)
        item.night.map(night => night.is_had_order = 0)
        return item
      })
      if (type === 'noon') {
        this.store.data.roomList[pIndex]['noon'][index]['is_had_order'] = 1
      } else {
        this.store.data.roomList[pIndex]['night'][index]['is_had_order'] = 1
      }
      this.setData({
        modal: false,
      })
      if (roomId !== '') {
        this.hideRoom()
        this.update()
      }
    }
  }
})
